<template>
    <div>
        <h1>修改</h1>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">房间名称</td>
                    <td><input type="text" v-model="info.Name"></td>
                </tr>
                <tr>
                    <td align="right">门市销售价格</td>
                    <td><input type="text"v-model="info.Price"></td>
                </tr>
                <tr>
                    <td align="right">房间数</td>
                    <td><input type="text"v-model="info.Num"></td>
                </tr>
                <tr>
                    <td align="right">状态</td>
                    <td><input type="radio" name="sta" v-model="info.State" :value="true">启用
                        <input type="radio" name="sta" v-model="info.State" :value="false">停用</td>
                </tr>
                <tr>
                    <td align="right">房间号</td>
                    <td><input type="checkbox" name="check" v-model="info.NumBer" value="102"/>102
                        <input type="checkbox" name="check" v-model="info.NumBer" value="103"/>103
                        <input type="checkbox" name="check" v-model="info.NumBer" value="205"/>205
                        <input type="checkbox" name="check" v-model="info.NumBer" value="207"/>207
                        <input type="checkbox" name="check" v-model="info.NumBer" value="301"/>301
                        <input type="checkbox" name="check" v-model="info.NumBer" value="406"/>406
                        <input type="checkbox" name="check" v-model="info.NumBer" value="508"/>508
                        <input type="checkbox" name="check" v-model="info.NumBer" value="403"/>403
                    </td>
                </tr>
                <tr>
                    <td align="right"></td>
                    <td><input type="button" value="修改" @click="ok"></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref,reactive,onMounted} from 'vue'
import axios from 'axios';
import { useRouter,useRoute } from 'vue-router';
const router=useRouter();
const route=useRoute();
let info:any=reactive({
  Id:route.query.id,
  Name: '',
  Price: '',
  Num: '',
  State: '',
  NumBer: [],
})
onMounted(()=>{
    getFind();
})
const getFind=()=>{
    axios({
        url:'/api/User/GetFind',
        method:'get',
        params:{
            id:route.query.id
        }
    })
    .then((res)=>{
        console.log(res);
        Object.assign(info,res.data)
        info.NumBer=res.data.NumBer.split('、')
    })
}
const ok=()=>{
    if(info.Name=="")
    {
        alert("名字不能为空");
        return;
    }
    if(info.NumBer=="")
    {
        alert("勾选不能少于一个");
        return;
    }
    
    axios({
        url:'/api/User/UpdateUser',
        method:'put' ,
        params:info
    })
    .then((res)=>{
        
        console.log(res);
        
        if(res.data==-1)
    {
        alert("名字重复")
    }
    if(res.data>0)
    {
        alert("添加成功")
        return
    }
    else{
        alert("添加失败")
        return
    }
    })
    .catch((err)=>{
        console.log(err);
        
    })
}
</script>

<style scoped>

</style>